package com.lebang.service.sys;

import com.lebang.entity.sys.Module;
import com.lebang.mapper.sys.ApplicationManagementMapper;
import com.lebang.model.enums.buss.ModuleType;
import com.lebangweb.response.Callback;
import com.lebangweb.response.JsonData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @author admin
 */
@Service
public class ApplicationManagementService {
    @Autowired
    private ApplicationManagementMapper applicationManagementMapper;

    public List<Map> recordOrderPage(Integer startNum, Integer limit, Map<String, Object> objectObjectHashMap) {
        return applicationManagementMapper.recordOrderPage(startNum, limit, objectObjectHashMap);
    }

    public Long recordOrderCount(Map<String, Object> objectObjectHashMap) {
        return applicationManagementMapper.recordOrderCount(objectObjectHashMap);
    }

    public JsonData sortSave(String table, Integer id, Integer sort) {
        int i = applicationManagementMapper.updateSortById(table, id, sort);
        if (i > 0) {
            return Callback.success("200", "操作成功", null);
        } else {
            return Callback.success("200", "操作失败", null);
        }
    }

    public JsonData moduleSave(Module module) {
        int i = 0;
        if (module.getId() != null) {
            i = applicationManagementMapper.updateByPrimaryKeySelective(module);
        } else {
            module.setType(ModuleType.Banner);

            i = applicationManagementMapper.insertSelective(module);
        }
        if (i > 0) {
            return Callback.success("200", "操作成功", null);
        } else {
            return Callback.success("200", "操作失败", null);

        }
    }

    public Module selectByid(Long id) {
        return applicationManagementMapper.selectByPrimaryKey(id);
    }

    public void updateModule(Module module) {
        applicationManagementMapper.updateByPrimaryKeySelective(module);
    }
}
